<template>
  <div class="personal">
    <router-link :to="'/editUserInfo/'+$route.params.id">
      <div class="profile">
        <!-- <img :src="axios.defaults.baseURL+current.head_img"
             alt /> -->
        <img :src="current.head_img"
             alt />
        <div class="profile-center">
          <div class="name">
            <span :class="{iconfont:true, iconxingbienan:current.gender == 1,iconxingbienv:current.gender == 0}"></span>{{current.nickname}}
          </div>
          <div class="time">{{current.create_date | dateFormat}}</div>
        </div>
        <span class="iconfont iconjiantou1"></span>
      </div>
    </router-link>
    <hmcell title="我的关注"
            desc='关注的用户'
            @click="$router.push({name: 'myfollows'})"></hmcell>
    <hmcell title="我的跟帖"
            desc='跟帖/回复'></hmcell>
    <hmcell title="我的收藏"
            desc='文章/视频'
            @click="$router.push({name: 'mystars'})"></hmcell>
    <hmcell title="设置"></hmcell>
    <hmbutton type='danger'
              style='margin-top:20px'
              @click="exit">退出</hmbutton>
  </div>
</template>

<script>
import hmcell from '@/components/hmcell.vue'
import hmbutton from '@/components/hmbutton.vue'

import { getUserInfo } from '@/apis/user.js'
// 引入之后可以在js中使用(不能在模板中直接使用)，但是并不是当前组件实例的成员
import axios from '@/utils/myaxios.js'
import { dateFormat } from '@/utils/myfilters.js'
export default {
  components: {
    hmcell, hmbutton
  },
  data () {
    return {
      current: {},
      // axios
    }
  },
  filters: {
    dateFormat
  },
  async mounted () {
    let res = await getUserInfo(this.$route.params.id)
    console.log(res);
    if (res.data.message == '获取成功') {
      // 渲染之前，对数据进行改造
      res.data.data.head_img = axios.defaults.baseURL + res.data.data.head_img
      this.current = res.data.data
    }
  },
  methods: {
    exit () {
      localStorage.removeItem('toutiao_59_token')
      localStorage.removeItem('toutiao_59_userinfo')
      this.$router.push({ path: '/index' })
    }
  }
}
</script>

<style lang='less' scoped>
.personal {
  width: 100vw;
  height: 100vh;
  background-color: #eee;
}
a {
  color: #666;
}
.profile {
  display: flex;
  padding: 20px 10px;
  justify-content: space-between;
  align-items: center;
  border-bottom: 5px #ddd solid;

  img {
    width: 70 / 360 * 100vw;
    height: 70 / 360 * 100vw;
    border-radius: 50%;
  }

  .profile-center {
    flex: 1;
    padding: 0 10px;
  }

  .name {
    span {
      color: #75b9eb;
    }
  }

  .time {
    color: #666;
    font-size: 14px;
    margin-top: 5px;
  }
}
</style>
